/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package threads;

import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Bertil
 */
public class Ex124 {
    public Ex124(){
        try {
            runner();
        } catch (InterruptedException ex) {
            Logger.getLogger(Ex124.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void runner() throws InterruptedException{
        XSimpleQueue buf = new XSimpleQueue();
        
        Scanner sc = new Scanner(System.in);
        System.out.println("Antal producenter? ");
            System.out.flush();
            Producent[] p = new Producent[sc.nextInt()];

        for(int i=0; i<p.length; i++){
            System.out.println("Producent nr " + (i+1) + ":");
            System.out.print(" Tidsintervall? ");
            System.out.flush();
            int time = sc.nextInt();
            System.out.print(" Text? ");
            System.out.flush();
            String txt = sc.next();
            p[i] = new Producent(txt, time, buf);
        }

        System.out.print(" Antal konsumenter? ");
            System.out.flush();
            Konsument[] k = new Konsument[sc.nextInt()];

        for(int i=0; i < k.length; i++){
            System.out.println("Konsument nr " + (i+1) + ":");
            System.out.print("   Tidsintervall? ");
                System.out.flush();
            int time = sc.nextInt();
            k[i] = new Konsument(time, buf);
        }

        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        for(int i=0; i < p.length; i++){
            p[i].activity.start();
        }
        for(int i=0; i < k.length; i++){
            k[i].activity.start();
        }
        Thread.sleep(60000);
        System.out.println("\nAntal kvar i kön: " + buf.size());
        System.exit(0);
    }
}
